<?php
if(!defined('BZ_XTBLOG') || !defined('BZ_WJSCUZ')) {
	exit('Access Denied');
}
$act=$_GET['act'];
$uid=verify_id($_GET['uid']);
$wzxx_title ='好友聊天-'.$wzxx_title.'';
$wzxx_gj    ='好友聊天-'.$wzxx_gj.'';
$wzxx_ms    ='好友聊天-'.$wzxx_ms.'';

if(!$user_uid){
   $pdid='1';
}elseif($act=='sms'){
	 $pdid='sms';
}elseif($act=='smsok'){
	 if(!$_POST['name']){
	 	   $mmts='短信内容不能为空！';
   }elseif(Bingz_config('sms_user_post') == '0'){
	     $mmts="系统关闭会员短信发送！";
   }elseif(!preg_match("/^1[0-9]{1}[0-9]{9}$/",$_POST[sms])){
	     $mmts="手机号格式错误！";
   }elseif(Bingz_sms_post($_POST['sms'],$_POST['name']) == '1'){
       $mmts="发送成功！";
   }else{
       $mmts="发送失败！";
   }
   $pdid='smsok';
}elseif($act=='ok'){
	 if(!$_POST['mm']){
	 	   $mmts='不能为空！';
	 }elseif($uid == $user_uid){
	 	   $mmts='不可以自言自语！';
	 }elseif( !$db->get_one('user'," `uid`= '$uid' ",'uid') ){
	 	   $mmts='会员uid出错！';
	 //}elseif( !$db->get_one('user_haoy'," `uid`= '$user_uid'  and `hyid`= '$uid'",'uid')){
	 	   //$mmts='Ta不是你的好友，不能聊天！';
	 }else{
		   Bingz_message_post($user_uid,$uid,$_POST[mm]);
	 	   $mmts='发送成功！';
   }
   $pdid='ok';
}elseif($act=='lt'){
   $hyname =$user_class->user_name($uid);
   if(!$uid){$hyname ='系统';}
   $num_count=$db->num_rows('message'," `fo_id` ='$uid' AND `to_id` ='$user_uid' OR `fo_id` ='$user_uid' AND `to_id` ='$uid' ",'id');
   $list_num ="15";
   $num_start=page_num($list_num,$num_count);
   $sql_bbs  =$db->query('message'," `fo_id` ='$uid' AND `to_id` ='$user_uid' OR `fo_id` ='$user_uid' AND `to_id` ='$uid' ORDER BY `time_a` DESC LIMIT ".$num_start." , ".$list_num." ",'');
   while($row_c=mysql_fetch_array($sql_bbs)){
             $tx='';
             $hypd='';
             $content='';
             $uidd='';
             $type='';
             $name=$user_class->user_name($row_c[fo_id]);
             $namey='';
             $namey=$user_class->user_name($row_c[fo_id],'1');
             $tx =$user_class->user_tx($row_c[fo_id]);
             if(!$row_c[fo_id]){
                 $name ='系统信息';
                 $tx ='images/user/xt.jpg';
             }
             if($row_c[fo_id] == $user_uid){
             	   $uidd=$row_c[fo_id];
                 $hypd ='1';
             }else{
             	   $uidd=$row_c[fo_id];
             }
             $sj=Bingz_time($row_c['time_a']);
             $content=$ubb->content_ubb($row_c[content]);
             if($row_c[to_id] == $user_uid && $row_c[type] == '1'){
             	  $type='1';
             }
             $sms[]=array('type' => $type,'content' => $content,'hypd' => $hypd,'sj' => $sj,'tx' => $tx,'sex'=> $sex,'uid'=> $uidd,'name'=> $name,'namey'=> $namey,'wd'=> $wd,'ts'=> $ts);
   }
   $db->update('message'," `type` ='0' "," `to_id` ='$user_uid' AND `fo_id` ='$uid'");
   $page=page_link($list_num,$num_count);
   $pdid='lt';
}else{
   $num_count=$db->num_rows('message'," `to_id` ='$user_uid' ORDER BY `id` DESC ",' distinct fo_id ');
   $list_num ="10";
   $num_start=page_num($list_num,$num_count);
   $sql_bbs  =$db->query('message'," `to_id` ='$user_uid' ORDER BY `id` DESC LIMIT ".$num_start." , ".$list_num." ",' distinct fo_id ');
   while($row_c=mysql_fetch_array($sql_bbs)){
             $tx='';
             $row='';
             $name =$user_class->user_name($row_c[fo_id]);
             $tx =$user_class->user_tx($row_c[fo_id]);
             $sex=$user_class->user_sex($row_c[fo_id]);
             if(!$row_c[fo_id]){
                 $name ='系统信息';
                 $tx ='images/user/xt.jpg';
             }
             $row=$db->get_one('message'," `to_id` ='$user_uid' ORDER BY `type` DESC LIMIT 0,1",'');
             $sj=Bingz_time_f($row['time_a']);
             $ts=$db->num_rows('message'," `fo_id` ='$row_c[fo_id]' AND `to_id` ='$user_uid' OR `fo_id` ='$user_uid' AND `to_id` ='$row_c[fo_id]'  ",' id');
             $wd=$db->num_rows('message',"`type` = '1' AND `to_id` = '$user_uid' and `fo_id` ='$row_c[fo_id]' ",' id');
             $sms[]=array('sj' => $sj,'tx' => $tx,'sex'=> $sex,'uid'=> $row_c[fo_id],'name'=> $name,'wd'=> $wd,'ts'=> $ts);
   }
   $page=page_link($list_num,$num_count);
}
@include template('head');
@include template('user/user_sms');
@include template('foot');
?>